package com.zjeav.lingjiao.ui.home.Find;

import android.app.Activity;
import android.graphics.Bitmap;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.annotation.RequiresApi;
import android.util.Log;
import android.view.ViewGroup;
import android.webkit.WebResourceError;
import android.webkit.WebResourceRequest;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.zjeav.lingjiao.R;

public class FindwebViewActivity extends Activity {

    private WebView webView;
    private boolean iswebview = false;

    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.findwebviewlayout);

        webView = findViewById(R.id.webView);

        String url = getIntent().getStringExtra("url");

        WebSettings webSettings = webView.getSettings();
        webSettings.setJavaScriptEnabled(true);// 支持JS
        webSettings.setJavaScriptCanOpenWindowsAutomatically(true);//支持通过js打开新的窗口
        webSettings.setRenderPriority(WebSettings.RenderPriority.HIGH);//提高渲染等级
        webSettings.setBuiltInZoomControls(false);// 设置支持缩放
        webSettings.setDomStorageEnabled(true);//使用localStorage则必须打开
        webSettings.setBlockNetworkImage(true);// 首先阻塞图片，让图片不显示
        webSettings.setBlockNetworkImage(false);//  页面加载好以后，在放开图片：
        webSettings.setSupportMultipleWindows(false);// 设置同一个界面
        webSettings.setBlockNetworkImage(false);
        webSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
        webSettings.setNeedInitialFocus(false);// 禁止webview上面控件获取焦点(黄色边框)
        webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
        if (webView!=null){
            if (iswebview){
                return;
            }
            iswebview = true;
            webView.setWebViewClient(new WebViewClient() {
                @Override
                public void onPageStarted(WebView view, String url, Bitmap favicon) {
                    super.onPageStarted(view, url, favicon);
                }

                @Override
                public void onPageFinished(WebView view, String url) {
                    super.onPageFinished(view, url);
                }

                @Override
                public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
                    super.onReceivedError(view, request, error);
                }

                @Override
                public boolean shouldOverrideUrlLoading(WebView view, String url) {
                    Log.i("","");
                    return true;
                }
            });

            webView.loadUrl(url);
        }

    }

    @Override
    protected void onResume() {
        super.onResume();
        Log.e("onResume","onResume....");
    }

}
